<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit|ie-comp|ie-stand">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<!--[if lt IE 9]>
    <script type="text/javascript" src="../../lib/html5shiv.js?rev=@@hash"></script>
    <script type="text/javascript" src="../../lib/respond.min.js?rev=@@hash"></script>
    <![endif]-->
		<link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css" />
		<link rel="stylesheet" type="text/css" href="../../lib/Hui-iconfont/1.0.8/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin" />
		<link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css" />
		<link rel="stylesheet" type="text/css" href="../../ht-css/Project.css" />
		<!--[if IE 6]>
    <script type="text/javascript" src="../../lib/DD_belatedPNG_0.0.8a-min.js?rev=@@hash"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
		<link rel="stylesheet" type="text/css" href="../../ht-css/style-q.css" />
		<title></title>
	</head>

	<body>
		<div class="ml-20 mt-20 mb-20 mr-20">
			<div class="">
				<label class="form-label f-l pt-5 text-r w-75" style="margin-left: 123px;">奖品名称：</label>
				<span class="select-box size-M radius mb-15" onclick="zhanshi()" style="background: #fff;width: 131px;">
        <select class="select" onchange="funas()" name="" id="names">
           	<option value="" selected="selected" >请选择奖品</option>
            <option value="10" >谢谢参与</option>
            <option value="20">满减劵</option>
            <option value="30">运费劵</option>
            <option value="40">手机</option>
            <option value="50">平板电脑</option>
            <option value="60">购物卡</option>
            <option value="70">赫力斯工具</option>
            <option value="80">水杯</option>
        </select>
        </span>
				<span id="tishi" style="color: #c62b26;display: none">请选择奖品名称</span>
			</div>
			<div class="formControls mb-20" id="youhui" style="display: none">
				<div class="">
					<label class="form-label f-l pt-5 text-r w-75" style="margin-left: 92px;width: 108px;">优惠券发券编码：</label>
						<input class="text" id="codes" autocomplete="off" onclick="gongsi()"  oninput="gongsi()">
					<span id="tishi2" style="color: #c62b26;display: none">请选择优惠券发券编码</span>
					<ul class="relation radius guanlian" id="tuank" style="width:156px;z-index: 1;    margin-top: -12px;margin-left: 200px;">
						<li>无数据</li>
					</ul>
				</div>

			</div>
			<div style="text-align: center;margin-top: 78px;">
				<a onclick="cancelBtn()" id="cancelBtn" class="btn btn-secondary radius size-S ml-20">取消</a>
				<a onclick="sureBtn()" id="sureBtn" class="btn btn-secondary radius size-S ml-20">确认</a>
			</div>
		</div>
	</body>
	<!--_footer 作为公共模版分离出去-->
	<script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js?rev=@@hash"></script>
	<script type="text/javascript" src="../../lib/layer/2.4/layer.js?rev=@@hash"></script>
	<script type="text/javascript" src="../../static/h-ui/js/H-ui.min.js?rev=@@hash"></script>
	<script type="text/javascript" src="../../static/h-ui.admin/js/H-ui.admin.js?rev=@@hash"></script>
	<!--/_footer 作为公共模版分离出去-->
	<!--请在下方写此页面业务相关的脚本-->
	<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js?rev=@@hash"></script>
	<!--表单验证-->
	<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/jquery.validate.js?rev=@@hash"></script>
	<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/validate-methods.js?rev=@@hash"></script>
	<script type="text/javascript" src="../../lib/jquery.validation/1.14.0/messages_zh.js?rev=@@hash"></script>
	<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js?rev=@@hash"></script>
	<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js?rev=@@hash"></script>
	<script src="../../ht-js/public.js?rev=@@hash"></script>
<!--验证token-->
<script src="../../ht-js/verifyToken.js?rev=@@hash"></script>
	<script src="../../ht-js/Project.js?rev=@@hash"></script>
	<script>
		var dianji=0
		//清空优惠劵编码
		function funas() {
			$("#codes").val("")
		}
		var shuj=""
		var amount=""//优惠劵面额
		var sendTotalNum=""//优惠劵数量
		var useCondition=""//使用条件
		function gongsi(){
            dianji=1
			var topicType=""
			if($("#names option:selected").val()==20){
				topicType=10
			}else {
				topicType=20
			}
			$.ajax({
				url:root.promotion.listCouponSendBySendCode,
				cache: false,  //禁用缓存
				type: "POST",
				dataType:'json',
				contentType: "application/json",
				data: JSON.stringify({
					"topicType":topicType,
					"sendCouponCode":$("#codes").val()
				}),
				success: function (data) {
					if(data.errorCode=="0"){
						var jsonObj =data.data;
						shuj=jsonObj
						if(jsonObj==null){
							$("#tuank").html("<li>无数据</li> ");
						}else {
							var optionstring = "";
							for (var  i= 0; i < jsonObj.length; i++) {
								optionstring += "<li  onclick='relation("+ jsonObj[i].sendCouponCode+","+1 +","+ jsonObj[i].amount+","+ jsonObj[i].sendTotalNum+","+ jsonObj[i].useCondition+")' data-align=\"" + jsonObj[i].sendCouponCode + "\" > " + jsonObj[i].sendCouponCode + "</li>";
							}
							$("#tuank").show()
							$("#tuank").html(optionstring);


						}
					}else{
						$("#tuank").html("<li>无数据</li> ");
					}

				},
				error: function () {
					$.Huimodalalert('失败！',2000);
				}
			})


		}

		$(document).bind("click",function(e){
			//id为menu的是菜单，id为open的是打开菜单的按钮
			if($(e.target).closest("#tuank").length == 0 && $(e.target).closest("#codes").length == 0){
				//点击id为menu之外且id不是不是open，则触发
				$("#tuank").hide()
			}
		})
		function relation(ce,id,amounts,sendTotalNums,useConditions) {
			$("#codes").val(ce).text(id)
			$("#tuank").hide()
			 amount=amounts//优惠劵面额
			 sendTotalNum=sendTotalNums//优惠劵数量
			useCondition=useConditions//使用条件
            dianji=0
		}

		//编辑时渲染
		xuan()
function xuan() {
	var zhis=sessionStorage.getItem("zhi")//奖品名称id
	var xuans=sessionStorage.getItem("xuan")//区分设置或编辑
	var codeids=sessionStorage.getItem("codeids")//优惠券发券编码
	if(xuans==123){
		$("#youhui").css({
			display: "none"
		});
	}else {
		if(zhis=="20"||zhis=="30"){
			$("#names").val(zhis)
			$("#codes").val(sessionStorage.getItem("codeids"))
			amount=sessionStorage.getItem("amountsall")
			$("#youhui").css({
				display: "inline"
			});
		}else {
			$("#names").val(zhis)
			$("#youhui").css({
				display: "none"
			});
		}
if($("#codes").val()!=""){
	/*amount=$("#codes").val()*/
	shuj=111111
}

		var topicType=""
		if($("#names option:selected").val()==20){
			topicType=10
		}else {
			topicType=20
		}

		$.ajax({
			url:root.promotion.listCouponSendBySendCode,
			cache: false,  //禁用缓存
			type: "POST",
			dataType:'json',
			contentType: "application/json",
			data: JSON.stringify({
				"topicType":topicType,
				"sendCouponCode":$("#codes").val()
			}),
			success: function (data) {
				if(data.errorCode=="0"){
					var jsonObj =data.data;
						for (var  i= 0; i < jsonObj.length; i++) {


							sendTotalNum=jsonObj[i].sendTotalNum

						}

				}
			},
			error: function () {
				$.Huimodalalert('失败！',2000);
			}
		})

	}
}
		function zhanshi() {
			if($("#names option:selected").val()!=""){
				$("#tishi").css({
					display: "none"
				});

				if($("#names option:selected").val()=="20"||$("#names option:selected").val()=="30"){
					$("#youhui").css({
						display: "inline"
					});
				}else {
					$("#youhui").css({
						display: "none"
					});
				}
			}

		}
		//保存
		function sureBtn() {
		    if($("#codes").val()==sessionStorage.getItem("codeids")){
                dianji=0
			}
		    console.log(amount)
            console.log(dianji)
			if($("#names option:selected").val()=="20"||$("#names option:selected").val()=="30"){
					if($("#codes").val()==""){
						$("#tishi2").css({
							display: "inline"
						});
						return false;
					}else {
						$("#tishi2").css({
							display: "none"
						});
					}
				if(shuj==null||shuj==""){
					$.Huimodalalert('<span style="font-size: 13px">优惠券发券编码已失效或者不存在请重新选择</span>',3000);
					return false;
				}
				if(amount==""|| dianji==1){
					$.Huimodalalert('请选择优惠券发券编码',3000);
					return false;
				}
			}


			if($("#names").val()==""){
				$("#tishi").css({
					display: "inline"
				});
			}else {
				$("#tishi").css({
					display: "none"
				});
				var Serials=sessionStorage.getItem("Serials")//序号
				sessionStorage.setItem("setupSerials",Serials)
				sessionStorage.setItem("jpnames",$("#names option:selected").text())//奖品名称
				sessionStorage.setItem("jpnid",$("#names option:selected").val())//奖品名称
				sessionStorage.setItem("codes",$("#codes").val())//优惠券发券编码
				sessionStorage.setItem("sendTotalNum",sendTotalNum)//优惠劵数量
				sessionStorage.setItem("amount",amount)//优惠劵面额
				sessionStorage.setItem("useCondition",useCondition)//使用条件
				window.parent.xuanran();
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
			}

		}

       //取消
		function cancelBtn() {
			parent.layer.closeAll();
		}
	</script>

</html>